package com.codi.fcloud.ufx;

import com.codi.base.util.Assert;
import com.codi.bus.constant.GlobalConstant;
import com.codi.fcloud.ufx.constant.HSOutputParameterNames;

import java.util.List;
import java.util.Map;

public class HsResponseUtil {

    /**
     * 统一恒生返回接口操作检查
     *
     * @param map
     * @return
     */
    public static boolean isOperationOk(Map<String, Object> map) {
        if (!map.containsKey(HSOutputParameterNames.SUCCESS_TYPE)) {
            return false;
        }

        String successType = map.get(HSOutputParameterNames.SUCCESS_TYPE).toString();
        if (successType.equals("0")) {
            return true;
        }

        return false;

// shi.pengyan 2017-9-27 17:48:13
//		if (StringUtils.isBlank((String) map.get("error_code"))) {
//			return true;
//		}
//		return false;
    }

    public static boolean isOperationOk(List<Map<String, Object>> op_res) {
        Assert.notEmpty(op_res);
        if (op_res.size() != 1) {
            return true;
        }
        Map<String, Object> first = op_res.get(0);
        return isOperationOk(first);
    }

    public static Map<String, Object> removeAdditionInfo(Map<String, Object> map) {
        String[] keys = {GlobalConstant.KEY_REQUEST, GlobalConstant.KEY_RESPONSE, GlobalConstant.KEY_API};
        for (int i = 0; i < keys.length; i++) {
            String key = keys[i];
            if (map.containsKey(key)) {
                map.remove(key);
            }
        }
        return map;
    }
}
